package com.starmark.message.queue.producer.api.factory;

import com.starmark.message.queue.producer.api.service.IMessageQueueProducerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @author starmark
 * @date 2020/5/1  下午2:25
 */
@Service
public class MessageQueueProducerFactory {
    @Autowired
    private List<IMessageQueueProducerService> messageQueueProducerServices;

    public IMessageQueueProducerService getMessageQueueProducerService(String producerType) {

        IMessageQueueProducerService producerService = messageQueueProducerServices.stream().filter(messageQueueProducerService -> messageQueueProducerService.support(producerType)).findFirst().orElse(null);
        Assert.notNull(producerService, "消息队列生产者不存在");
        return producerService;
    }
}


